var builder = require("../../mlib/layer/builder");
var merge = require("mlib/json/merge");
var infoRender = require("../layer/info.ejs");
module.exports = function(msg,opts,callback) {
    opts = merge({        
        content : msg || "", // 消息内容
        time : 3000, // 自动关闭所需毫秒
        icon: null, // 消息图标
        text : "",  // 消息图标文本
        mask : false // 是否显示遮罩
    }, opts || {});
    var aTimer = null ;
    var m_info = null ;
    var _autoClose = null ;

    _autoClose = function(){
        clearTimeout(aTimer);
        aTimer = window.setTimeout(function(){	
           callback && callback();		
           m_info.hide();
        }, opts.time);
    };

    m_info = builder.createFromHTML(infoRender(opts), {
        "mask": false
    });

    m_info.show({
    	"afterAnimate":function(){
			if( opts.time > 0 ){
			    _autoClose();
			}
    	}
    });
   var scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
   var mx = (document.documentElement.clientWidth-m_info.getOuter().clientWidth)/2;
   var my = (document.documentElement.clientHeight-m_info.getOuter().clientHeight)/2 + scrollTop;
   // m_info.setMiddle();
    m_info.setPosition(mx+"px",my+"px");
}

